<?php
	/*
	 * All rights Reserved, Designed By www.youyacao.com <br>
	 * @Description:轮播图 <br>
	 * @version 蜻蜓C影视追剧系统  <br>
	 * @author:成都市一颗优雅草科技有限公司  <br>
	 * 注意：使用我司开源源代码请遵循license文件的协议仅供个人非盈利使用，禁止用于其他的商业用途
	 * 需要商业用途或者定制开发等可访问songshu.youyacao.com  联系QQ:2853810243 422108995 23625059584
	 * 正版系统查询系统 zhengbancha.youyacao.com
	 */


namespace App\Admin\Controllers;

use App\Admin\Repositories\Carousel;
use App\Models\Episode;
use App\Models\Mp;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class CarouselController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Carousel(['mps', 'eps']), function (Grid $grid) {
            $grid->model()->orderByDesc('created_at');
            $grid->quickSearch('eps.name', 'mps.name')->placeholder('可搜索小程序名称,剧集名称');
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('url', '图片')->image('', 100, 100);
            $grid->column('sort')->editable();
            $grid->column('eps.name', '剧集');
            $grid->column('mps.name', '小程序');
            $grid->column('goto', '页面跳转')->editable();
            $grid->column('status')->switch();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Carousel(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('url');
            $show->field('sort');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Carousel(), function (Form $form) {
            $form->display('id');
            $form->text('name')->required();
            $form->select('mps_id', '归属小程序')->options(Mp::pluck('name', 'id'))->required();
            $form->image('url', '图片')->accept('jpg,png,gif,jpeg')->autoUpload()->saveFullUrl()->required();
            $form->number('sort')->help('值越大越靠前')->required();
            $form->select('episodes_id', '关联剧集')->options(Episode::pluck('name', 'id'))->required();
            $form->text('goto', '页面跳转')->help('页面地址从前端获取');
            $form->radio('status')->options([0=>'禁用',1=>'启用'])->default(1);

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
